/*
 * @lc app=leetcode id=447 lang=cpp
 *
 * [447] Number of Boomerangs
 */

// @lc code=start
class Solution {
public:
    int numberOfBoomerangs(vector<vector<int>>& points) {
        int n = points.size();
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            map<int, int> table;
            for (int j = 0; j < n ; ++j) {
                if (i == j) {
                    continue;
                }
                int x = points[j][0] - points[i][0];
                int y = points[j][1] - points[i][1];
                int distance = x  * x + y * y;
                if (table.count(distance) > 0) {
                    table[distance]++;
                } else {
                    table[distance] = 1;
                }
            }
            for (auto iter : table) {
                if (iter.second >= 2) {
                    ans += (iter.second - 1) * iter.second;
                }
            }
        }
            return ans;

    }
};
// @lc code=end

